<div class="admin_left actions">
	<h3><?php echo __('Actions'); ?></h3>
	<ul>

		<li style="list-style-type:none; margin-bottom:20%;"><?php echo $this->Html->link(__('List Consignments'), array('action' => 'index'),array('class' => 'consistentButton2')); ?></li>
		<li style="list-style-type:none; margin-bottom:20%;"><?php echo $this->Html->link(__('List Items'), array('controller' => 'items', 'action' => 'index'),array('class' => 'consistentButton2')); ?> </li>
		<li style="list-style-type:none; margin-bottom:20%;"><?php echo $this->Html->link(__('New Item'), array('controller' => 'items', 'action' => 'add'),array('class' => 'consistentButton2')); ?> </li>
		<li style="list-style-type:none; margin-bottom:20%;"><?php echo $this->Html->link(__('List Consigners'), array('controller' => 'consigners', 'action' => 'index'),array('class' => 'consistentButton2')); ?> </li>
		<li style="list-style-type:none; margin-bottom:20%;"><?php echo $this->Html->link(__('New Consigner'), array('controller' => 'consigners', 'action' => 'add'),array('class' => 'consistentButton2')); ?> </li>
	</ul>
</div>

<div class="admin_right consignments form">

        <div id=breadcrumbAdmin>
            <?php $this->Html->addCrumb('Consignments', '/Consignments/index'); ?>
            <?php $this->Html->addCrumb('Add', '/Consignments/add', array('style'=> ('text-decoration:underline; color:#EB1E70;'))); ?>
            <?php echo $this->Html->getCrumbs(' > ', array( 'text' => 'Transactions', 'url' => array('controller' => 'sales', 'action' => 'index'), 'escape' => false)); ?>
        </div>

<?php echo $this->Form->create('Consignment'); ?>
	<fieldset>
		<legend><?php echo __('Add Consignment'); ?></legend>
		
		
<div id='TextBoxesGroup'>
	<div id="TextBoxDiv0" style="height:60px">
		<?php echo $this->Form->input('ConsignmentItem.0.item_id'); ?>
		<?php 
		echo $this->Form->button('New Item', array('type'=> 'button', 'class' => 'item-popup-window','onclick'=>'itempopupopen()'));
		?>
	</div>
</div>
<div style="margin:10px">
	<?php
        echo $this->Form->button('Add Item', array('type'=> 'button', 'id' => 'addButton'));
        echo $this->Form->button('Remove Item', array('type'=> 'button', 'id' => 'removeButton'));
	?>
</div>
	<?php
		echo $this->Form->hidden('count', array('value'=> '1'));
				
		echo $this->Form->input('Consignment.consigner_id');
        echo $this->Form->button('New Consigner', array('type'=> 'button', 'class' => 'consigner-popup-window'));
		echo $this->Form->input('Consignment.note');
	?>
	</fieldset>
	

<?php echo $this->Form->end(__('Submit')); ?>
</div>


<script type="text/javascript">

    $(document).ready(function() {
	
        $('.consigner-popup-window').click(function(){

           var popupBoxConsigner = '#popup-box-consigner';

           $(popupBoxConsigner).fadeIn(400);

           var popMargTop = ($(popupBoxConsigner).height() + 24) /2;
           var popMargLeft = ($(popupBoxConsigner).height() + 24) /2;

           $(popupBoxConsigner).css({
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
           });

           $('body').append('<div id="mask"></div>');
           $('#mask').fadeIn(400);
           return false;

        });
		


        $('button.close, #mask').bind('click', function(){
            $('#mask, #popup-box-item, #popup-box-consigner').fadeOut(400, function(){
                $('#mask').remove();
            });
            return false;

        });




    });
	
$(document).keyup(function(e) {
    if ( e.keyCode == 27) {
        $('#mask, #popup-box-item, #popup-box-consigner').fadeOut(400);
        return false;
    }
});

function itempopupopen()
{
	var popupBoxItem = '#popup-box-item';
	
	$(popupBoxItem).fadeIn(400);
	
	var popMargTop = ($(popupBoxItem).height() + 24) /2;
	var popMargLeft = ($(popupBoxItem).height() + 24) /2;
	
	$(popupBoxItem).css({
	'margin-top' : -popMargTop,
	'margin-left' : -popMargLeft
	});
	
	$('body').append('<div id="mask"></div>');
	$('#mask').fadeIn(400);
	return false;
}

</script>
<!-- end  function -->

<!-- popup button for Consigner begins -->
<?php echo $this->Html->script('jquery.form'); ?>
<div id="popup-box-consigner" class="popupInfo">
	<?php echo $this->Form->create('Consigner',array("url"=>array("controller"=>"consigners"))); ?>
	<h4>New consigner:</h4>
	<input type="hidden" value="<?php echo rand(1000, 9999)?>" name="random" style="height:25px;" />
    <?php echo $this->Form->input('name',array("type"=>"text")); ?>
    <?php echo $this->Form->input('Email',array("type"=>"text")); ?>
    <?php echo $this->Form->input('Phone',array("type"=>"text")); ?>
    <?php echo $this->Form->input('Address',array("type"=>"text")); ?>
    <?php echo $this->Form->input('Note',array("type"=>"text")); ?>

	<button type="button" class="close">Close</button><br>
	<?php echo $this->Form->end(__('Submit')); ?>

</div>

<script type="text/javascript">
$(document).ready(function(){
	 $('#ConsignerAddForm').ajaxForm({
		 complete: function (xhr) {
			 var data = JSON.parse(xhr.responseText);
			 alert(data.message);
			 //Save successful, reload page
			 if(data.status){
				 $("#ConsignmentConsignerId").empty();
				 $.each(data.consignerlist,function(index,elem){
					 $("#ConsignmentConsignerId").append("<option value="+elem.id+">"+elem.name+"</option>");
					 });
				}
			$('#mask, .popupInfo').fadeOut(400);
			$("#ConsignerAddForm #ConsignerName").val("");
		    return false;
		   }
		});

});
</script>
<!-- popup button for Consigner ends -->

<!-- popup button for item begins -->

<?php echo $this->Html->script('jquery.form'); ?>
<div id="popup-box-item" class="popupInfoItem">

     <div id="infoleft">	
	<?php echo $this->Form->create('Item',array("url"=>array("controller"=>"Items"),'type'=>'file')); ?>
        <?php //echo $this->Form->create('Item',array('type'=>'file')); ?>
        <h4>New Item</h4>
        <input type="hidden" value="<?php echo rand(1000, 9999)?>" name="random" style="height:25px;" />
        <?php echo $this->Form->input('Item.name',array("type"=>"text")); ?>
		
    	<?php		
		$is_consignments = array('Consignment' => 'Consignment', 'normal' => 'normal');
		echo $this->Form->input('Item.is_consignment', array('options' => $is_consignments, 'default' => 'normal'));
		?>
		
        <?php echo $this->Form->input('Item.brand_id',array("url"=>array('controller'=>'items'))); ?>
        <?php echo $this->Form->input('Item.color_id',array("url"=>array('controller'=>'items'))); ?>
        <?php echo $this->Form->input('Item.condition_id',array("url"=>array('controller'=>'items'))); ?>
        <?php echo $this->Form->input('Item.size_id',array("url"=>array('controller'=>'items'))); ?>
        <?php echo $this->Form->input('Item.category_id',array("url"=>array('controller'=>'items'))); ?>


        <?php echo $this->Form->input('Item.item_status_id',array("url"=>array('controller'=>'items'))); ?>


     </div>

    <div id="inforight">

        <?php echo $this->Form->input('Item.description'); ?>
     <?php $onlines = array('Yes' => 'Yes', 'No' => 'No'); ?>
        <?php echo $this->Form->input('Item.online', array('options' => $onlines, 'default' => 'No')); ?>

       <?php $locations = array_combine( array('Backstorage', 'Shelf'),array('Backstorage', 'On Display')); ?>
        <?php echo $this->Form->input('Item.location', array('options' => $locations, 'default' => 'Backstorage')); ?>
        <?php echo $this->Form->input('Item.original_price'); ?>
        <?php $is_discounted = array('Yes' => 'Yes', 'No' => 'No'); ?>
        <?php echo $this->Form->input('Item.is_discounted', array('options' => $is_discounted, 'default' => 'No'));?>
       <!-- <?php echo $this->Form->input('image_id'); ?> -->

        <div class="addPhotosFields" id="addPhotosFields">
        <?php
         echo $this->Form->input('Image.0.name', array('label' => false, 'div' => false, 'type' => 'file', 'class' => 'addPhotoButton'));
         echo $this->Form->input('Image.1.name', array('label' => false, 'div' => false, 'type' => 'file', 'class' => 'addPhotoButton'));
         echo $this->Form->input('Image.2.name', array('label' => false, 'div' => false, 'type' => 'file', 'class' => 'addPhotoButton'));
         echo "<input type='button' id='more-fields' onclick='addFields();' value='Add more images' />";
          ?>
        <button type="button" class="close">Close</button><br>
        <?php echo $this->Form->end(__('Submit')); ?>
        </div>
    </div>


<script type="text/javascript">
$(document).ready(function(){
	 $('#ItemAddForm').ajaxForm({
		 complete: function (xhr) {
			 var data = JSON.parse(xhr.responseText);
			 alert(data.message);
			 //Save successful, reload page
			 if(data.status){
		
				 loopc = $('#ConsignmentCount').val();
				 for(count=0;count<loopc;count++)
				 {					 	
					 $("#ConsignmentItem"+ count +"ItemId").empty();					
				 }
					 
				 $.each(data.itemlist,function(index,elem){
				 
					 
					 for(count=0;count<loopc;count++)
					 {					 	
						 $("#ConsignmentItem"+ count +"ItemId").append("<option value="+elem.id+">"+elem.name+"</option>");
					 }
					 
					 });
				}
			$('#mask, .popupInfoItem').fadeOut(400);
			$("#ItemAddForm #ItemName").val("");
		    return false;
		   }
		});		
		
	
});
</script>
<!-- popup button for item ends -->


<?php echo $this->Html->script('jquery-1.3.2.min.js');?>
				
<script>var jQuery132 = $.noConflict(true);</script>

<script type="text/javascript">
 
jQuery132(document).ready(function(){
 
    var counter = 1;
 
    jQuery132("#addButton").click(function () {

 
	var newTextBoxDiv = jQuery132(document.createElement('div'))
	     .attr("id", 'TextBoxDiv' + counter);
 
	newTextBoxDiv.after().html('<div class="input select"><label for="ConsignmentItem'+ counter +'ItemId">Item</label><select name="data[ConsignmentItem]['+ counter +'][item_id]" id="ConsignmentItem'+ counter +'ItemId"></select></div><button class="item-popup-window" type="button" onclick="itempopupopen()">New Item</button>');
	
	
		jQuery132.get("<?php echo $webroot?>Consignments/itemdropdown/",function(data){	
				
			
			 var data = JSON.parse(data);
	
				 jQuery132.each(data.itemlist,function(index,elem){
				 jQuery132('#ConsignmentItem'+ (counter-1) +'ItemId').append("<option value="+elem.id+">"+elem.name+"</option>");									 
					 });
			
			});			
		
 
		newTextBoxDiv.appendTo("#TextBoxesGroup"); 

		counter++;
		
		$("#ConsignmentCount").val(counter);
		
     });
 
	jQuery132("#removeButton").click(function () {
	
	if(counter==1){	alert("You have to select at least one item for consignment");	return false;	}   
	
	counter--;
	
	jQuery132("#TextBoxDiv" + counter).remove();
		
	});	

  });
</script>
